#include "Zhuce.h"
#include "ui_Zhuce.h"

#include <QMessageBox>

Zhuce::Zhuce(QRect screenGeometry,QWidget *parent) :
    QDialog(parent),
    ui(new Ui::Zhuce)
{
    ui->setupUi(this);
    this->setGeometry(0,0,screenGeometry.width(),screenGeometry.height());
}

Zhuce::~Zhuce()
{
    delete ui;
}

void Zhuce::MessageBoxData(QString str)
{
    QMessageBox *box=new QMessageBox;
    box->warning(nullptr,"",str);
    box->exec();
    delete box;
}


void Zhuce::on_yes_clicked()
{
    QRegExp idCardRegex("^1\\d{10}$");
    bool r=idCardRegex.exactMatch(ui->phone->text());
    if(!r)
    {
        this->MessageBoxData("手机号输入有误");
        return;
    }

    if(this->ui->pass_one->text()!=this->ui->pass_two->text())
    {
        this->MessageBoxData("两次的密码不一致");
    }
    else if(this->ui->pass_one->text()==this->ui->pass_two->text() && this->ui->pass_one->text()!="")
    {
        QString str="7E7E;kind:phone;function:00;phone:%1;pass:%2;";
        str=str.arg(this->ui->phone->text()).arg(this->ui->pass_one->text());
        emit this->sendServerData(str);
    }
    else if(this->ui->pass_one->text()==this->ui->pass_two->text() && this->ui->pass_one->text()=="")
    {
        this->MessageBoxData("密码不能为空");
    }
}

void Zhuce::on_no_clicked()
{
    this->hide();
}

void Zhuce::zhuCeStatus(bool r, QString reason)
{
    if(r)
        reason="注册成功";
    this->MessageBoxData(reason);
    if(r)
        this->hide();
}
